package com.ssm.xml.controller;

import com.alibaba.fastjson.JSON;
import com.ssm.xml.entity.Article;
import com.ssm.xml.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Charles
 * @date 2022/4/27 0027 23:03
 */

@RestController
@RequestMapping("/art")
public class ArticleController {
   @Autowired
   private ArticleService articleService;
   @RequestMapping("/getAll")
    public String getALlArticleByDir(int dir){
       return JSON.toJSONString(articleService.getAllArticleByDir(dir));
   }
   @RequestMapping("/add")
    public String addArticle(Article article){
       articleService.addArticle(article);
       return "redirect:dir";
   }
   @RequestMapping("/delete")
    public String deleteArticle(int id){
       articleService.deleteArticle(id);
       return "redirect:dir";
   }
   @RequestMapping("/update")
    public String updateArticle(Article article){
       articleService.updateArticle(article);
       return "redirect:dir";
   }
}
